﻿using org.osgi.framework;
using System;
using System.Collections.Generic;
using System.Text;
using golion.calc;

namespace golion.console
{
    public class Class1 : BundleActivator
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        private static BundleContext bundleContext;
        public static BundleContext getBundleContext()
        {
            return bundleContext;
        }
        
        Ionic.Zip.ZipFile a = null;
        public void start(BundleContext context)
        {
            bundleContext = context;
            a = new Ionic.Zip.ZipFile();

            ServiceReference reference = bundleContext.getServiceReference(typeof(CalcService).FullName);
            if (reference == null)
            {
                log.Warn("未找到服务引用！！！");
                return;
            }
            CalcService calcService = bundleContext.getService(reference) as CalcService;

            DateTime startTime = DateTime.Now;
            for (int i = 0; i < 10000000; i++)
            {
                calcService.Mul(483433, 5843959);
            }
            log.Info("golion.console:用时：" + (DateTime.Now - startTime).ToString());

            int x = 43;
            int y = 98;
            log.Info(String.Format("{0} + {1} = {2}", x, y, calcService.Add(x, y)));
        }

        public void stop(BundleContext context)
        {

        }
    }
}
